package com.cn.dao;

import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.List;

import com.cn.conn.DataManager;
import com.cn.conn.ParamSet;
import com.cn.conn.RowDatas;
import com.cn.entity.Cycle_image_entity;


public class backstage_cycle_image_dao extends DataManager {
	private RowDatas<Cycle_image_entity> img;
	public backstage_cycle_image_dao() {
		img=new Member();
	}
	public List<Cycle_image_entity> getmember(){
		String sql=" SELECT * from tb_cycle_image";
			return  queryList(sql, img);
	}
	
	public int Upimg(int id,String url,String title){
		String sql="UPDATE tb_cycle_image SET url=? ,title=?   WHERE id=?";
		return updateExecuted(sql, new ParamSet(url,title,id));
		
	}
	public int addimg(String url,String title){
		String sql="INSERT into tb_cycle_image (url,title) VALUES (?,?)";
		return updateExecuted(sql, new ParamSet(url,title));
	}
	public int deletimg(int id){
		String sql="DELETE FROM tb_cycle_image WHERE id=?";
		int a=updateExecuted(sql, new ParamSet(id));
		if(a!=-1){
			System.out.println("删除成功");
		}else{
			System.out.println("删除失败");
		}
		return a;
	}
	public void deletimgs(String[] list){
		for(int a=0;a<list.length;a++){
			int imgg =Integer.parseInt(list[a]);
			this.deletimg(imgg);
		}
	}
	private class Member implements RowDatas<Cycle_image_entity>{

		@Override
		public Cycle_image_entity getRowData(ResultSet rs) throws SQLException {
			Cycle_image_entity img=new  Cycle_image_entity();
			img.setTitle(rs.getString("title"));
			img.setUrl(rs.getString("url"));
			img.setId(rs.getInt("id"));
			return img;
		}
		
	}
	
}
